package apphttp

import (
	"net/http"
	"TanguyWeb/main/utils"
	"html/template"
	"TanguyWeb/main/bean"
)

func htmlTest(w http.ResponseWriter, r *http.Request) error {
	if r.Method == "GET" {
		t, err := template.ParseFiles(fileutils.ViewRootPath + "test2.html")
		if err != nil {
			return bean.NewResultError(-1, "网页加载失败")
		}
		//t2 := template.New("新的模板")                                         //创建模板
		//t2.Funcs(map[string]interface{}{"tihuan": "555"})                  //向模板中注入函数
		//bytes, err := ioutil.ReadFile(fileutils.ViewRootPath + "test2.html") //读文件
		//checkErr(err)
		//template.Must(t2.Parse(string(bytes)))                             //将字符串读作模板
		//t2.Execute(w, map[string]interface{}{"UserName": "你好世界"})
		//fmt.Println("\n", t2.Name(), "\n")
		slice := make(map[int]string)
		slice[1] = "1--"
		slice[2] = "2--"
		slice[3] = "3--"
		slice[4] = "4--"
		t.Execute(w, map[string]interface{}{
			"aa":        "555",
			"Bbbb":      "bbbbb",
			"Condition": "bbb",
			"Slice":     slice,
			"Html":      slice,
		})

		//add := func(a, b int) (int) {
		//	return a + b
		//}
		//maps := make(template.FuncMap)
		//maps["add"] = add
		//t.Funcs(maps)
		//t.Execute(w, Article{Aaa: 111, Bbb: "bbbb"})
	}

	return nil
}

type Article struct {
	Aaa int
	Bbb string
}
